/*
    Project:        Home Power Control
    File:           HPCUserInput.cpp
    Author:         christian@karunamusic.at
    Date:           02.2015
    Description:    Read commands from the keyboard.
 */

#include <QTextStream>
#include <QString>
#include <QStringList>
#include <unistd.h>
#include "HPCUserInput.h"

HPCUserInput::HPCUserInput()
    : QObject()
{
}

HPCUserInput::~HPCUserInput()
{
}

void HPCUserInput::Run()
{
    QTextStream kbd(stdin);
    QTextStream out(stdout);

    QString cmd;
    bool r = true;

    while ( r )
    {
        out << "hpc> ";
        out.flush();

        cmd = kbd.readLine();
        if ( cmd.length() )
        {
            r = (cmd != "exit");
            emit command(cmd);
            usleep(100000);
        }
    }
    emit finished();
}
